package com.cfg.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
@TableName("cfg_category_entry")
public class CfgCategoryEntry {

    public CfgCategoryEntry()
    {

    }


    private static final long serialVersionUID = 1L;

    /** 编码ID */
    @TableId(value = "id",type = IdType.ASSIGN_UUID)
    private String id;

    //
    @TableField("code")
    private String code;

    //
    @TableField("categoryId")
    private String categoryId;
    @TableField("name")
    private String name;

    /** 子部门 */
    @TableField(exist = false)
    private List<CfgCategoryEntry> children = new ArrayList<CfgCategoryEntry>();

    public CfgCategoryEntry(SimpleCfgCategoryMapping simpleCfgCategoryMapping)
    {
        this.code = simpleCfgCategoryMapping.getCodeColumn();
        this.name = simpleCfgCategoryMapping.getValueColumn();
        this.children = simpleCfgCategoryMapping.getChildren().stream().map(CfgCategoryEntry::new).collect(Collectors.toList());
    }
}
